package com.hrzyit.whistle.user.data.repository

import com.hrzyit.base.data.net.RetrofitFactory
import com.hrzyit.base.data.protocol.BaseResp
import com.hrzyit.whistle.user.data.api.UserApi
import com.hrzyit.whistle.user.data.bean.UserInfo
import com.hrzyit.whistle.user.data.protocol.ForgetPwdReq
import com.hrzyit.whistle.user.data.protocol.LoginReq
import com.hrzyit.whistle.user.data.protocol.ResetPwdReq
//import rx.Observable
import io.reactivex.Observable
import javax.inject.Inject

/**
 * 用户模块数据操作类
 * @author YangWei
 * @date 2019/3/23
 */
class UserRepository @Inject constructor() {

    /**
     * 用户登录逻辑
     */
    fun login(
        userName: String, mobile: String, pwd: String, pushId: String
    ): Observable<BaseResp<UserInfo>> {
        return RetrofitFactory.instance
            .create(UserApi::class.java).login(
                LoginReq(
                    userName, mobile, pwd, pushId
                )
            )
    }

    /**
     * 用户忘记密码逻辑
     */
    fun forgetPwd(mobile: String, verifyCode: String): Observable<BaseResp<Boolean>> {
        return RetrofitFactory.instance
            .create(UserApi::class.java)
            .forgetPwd(
                ForgetPwdReq(mobile, verifyCode)
            )
    }

    /**
     * 重置密码逻辑
     */
    fun resetPwd(mobile: String, newPwd: String): Observable<BaseResp<UserInfo>> {

        return RetrofitFactory.instance
            .create(UserApi::class.java)
            .resetPwd(
                ResetPwdReq(mobile, newPwd)
            )
    }
}